package com.yonyou.crm.bpub.topbar.service;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.bpub.topbar.entity.*;
import com.yonyou.crm.common.filter.entity.AppFilterTypeConstant;
import com.yonyou.crm.common.search.entity.AppSearchPlanEnum;
import com.yonyou.crm.common.sort.entity.AppSortPlanEnum;
import com.yonyou.crm.sprc.oppstage.entity.OppstageVO;
import com.yonyou.crm.sprc.oppstage.service.OppstageBizServiceImpl;
import com.yonyou.crm.sys.modules.entity.MtObjTypeEnum;

@Service
public class OpportunityTopbar extends BaseTopbar {

	@Autowired 
	OppstageBizServiceImpl oppstageService;
	
	@Override
	public PlanVO getPresetOptions(){
		PlanVO presetOption = new PlanVO();
		presetOption.setTitle("预置选择");
		
		List<DataItemVO> data = new ArrayList<>();
		DataItemVO item;
		
		item = new DataItemVO(String.valueOf(AppSearchPlanEnum.ALL.getValue()), AppSearchPlanEnum.ALL.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSearchPlanEnum.OWNER.getValue()), AppSearchPlanEnum.OWNER.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSearchPlanEnum.REL.getValue()), AppSearchPlanEnum.REL.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSearchPlanEnum.FOLLOW.getValue()), AppSearchPlanEnum.FOLLOW.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSearchPlanEnum.OVERDUE.getValue()), AppSearchPlanEnum.OVERDUE.getName());
		data.add(item);
		
		presetOption.setData(data);
		return presetOption;
	};
	
	@Override
	public String getSearchPlaceholder(){
		String searchText = "搜索商机名称";
		return searchText;
	}
	
	@Override
	public PlanVO getSortData(){
		PlanVO sortData = new PlanVO();
		sortData.setTitle("排序");
		
		List<DataItemVO> data = new ArrayList<>();
		DataItemVO item;
		
		item = new DataItemVO(String.valueOf(AppSortPlanEnum.WINPROBABILITY.getValue()), AppSortPlanEnum.WINPROBABILITY.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSortPlanEnum.EXPECTEDSIGNTIME.getValue()), AppSortPlanEnum.EXPECTEDSIGNTIME.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSortPlanEnum.EXPECTEDSIGNAMOUNT.getValue()), AppSortPlanEnum.EXPECTEDSIGNAMOUNT.getName());
		data.add(item);
		
		item = new DataItemVO(String.valueOf(AppSortPlanEnum.MODIFYTIME.getValue()), AppSortPlanEnum.MODIFYTIME.getName());
		data.add(item);

		sortData.setData(data);
		return sortData;
	};
	
	@Override
	public List<SelectDataVO> getSelectData(){
		List<SelectDataVO> selectData = new ArrayList<SelectDataVO>();
		
		SelectDataVO select;
		List<DataItemVO> data;
		DataItemVO item;
		
		select = new SelectDataVO();
		select.setKey("owner");
		select.setType(AppFilterTypeConstant.Refer);
		select.setTitle("商机负责人");
		select.setReferto("user");
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("deptId");
		select.setType(AppFilterTypeConstant.Refer);
		select.setTitle("所属部门");
		select.setReferto("dept");
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("expectSignTime");
		select.setType(AppFilterTypeConstant.DateRanger);
		select.setTitle("预计签单时间");
		data = new ArrayList<>();
		item = new DataItemVO("start","开始时间");
		data.add(item);
		item = new DataItemVO("end","结束时间");
		data.add(item);
		select.setData(data);
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("winProbability");
		select.setType(AppFilterTypeConstant.NumberRanger);
		select.setTitle("赢单概率(%)");
		data = new ArrayList<>();
		item = new DataItemVO("min","最小值");
		data.add(item);
		item = new DataItemVO("max","最大值");
		data.add(item);
		select.setData(data);
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("types");
		select.setType(AppFilterTypeConstant.Multiple);
		select.setTitle("商机类型");
		data = getBizTypeList(MtObjTypeEnum.OPPORTUNITY.getName());
		select.setData(data);
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("saleStages");
		select.setType(AppFilterTypeConstant.Multiple);
		select.setTitle("商机阶段");
		data = new ArrayList<>();
		List<OppstageVO> stageList = oppstageService.getStageByTenant();
		if ((stageList != null) && (stageList.size() > 0)) {
			for(OppstageVO stageItem : stageList) {
				item = new DataItemVO(String.valueOf(stageItem.getId()), stageItem.getName());
				data.add(item);
			}
		}
		select.setData(data);
		selectData.add(select);
		
		select = new SelectDataVO();
		select.setKey("sources");
		select.setType(AppFilterTypeConstant.Multiple);
		select.setTitle("商机来源");
		data = getEnumListFromDoc("17", "opportunity_source");
		select.setData(data);
		selectData.add(select);
		
		return selectData;
	}

}
